package com.topinfo.etl.controller;

import com.jpx.component.model.service.IModelService;
import com.topinfo.component.base.bean.JsonResponse;
import com.topinfo.component.base.controller.AbstractModelController;
import com.topinfo.etl.bean.EtlDatasourceCfg;

import com.topinfo.etl.service.EtlDatasourceCfgService;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * 数据源配置信息
 */
@Controller
@RequestMapping("/etl/etldatasourcecfg")
public class EtlDatasourceCfgController extends AbstractModelController<EtlDatasourceCfg> {

    @Resource
    private EtlDatasourceCfgService etlDatasourceCfgService;

    @Override
    protected IModelService<EtlDatasourceCfg> getModelService() {
        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
        this.etlDatasourceCfgService.setRequest(request);
        return this.etlDatasourceCfgService;

    }

    @RequestMapping(value = "/connTest", method = {RequestMethod.POST})
    @ResponseBody
    public JsonResponse connTest(EtlDatasourceCfg model, BindingResult result) {
        return this.etlDatasourceCfgService.connTest(model);
    }
}
